package org.chen.spring.cloud.finchley.zuul.client;

import org.springframework.beans.factory.annotation.Value;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.cloud.client.discovery.EnableDiscoveryClient;
import org.springframework.security.oauth2.config.annotation.web.configuration.EnableResourceServer;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;
import java.util.Enumeration;

/**
 * @author chensj
 * @date 2020-02-11 21:45
 */
@SpringBootApplication
@EnableDiscoveryClient
@EnableResourceServer
@RestController
public class ZuulClientApplication {

    public static void main(String[] args) {
        SpringApplication.run(ZuulClientApplication.class, args);
    }

    @Value("${spring.application.name}")
    private String applicationName;

    @RequestMapping(value = "/test")
    public String test(HttpServletRequest request) {
        System.out.println("--------------header-----------------");
        Enumeration<String> headerNames = request.getHeaderNames();
        while (headerNames.hasMoreElements()) {
            String key = (String) headerNames.nextElement();
            System.out.println("Header key:" + key + " : " + request.getHeader(key));
        }
        System.out.println("--------------header-----------------");
        return "Hello , come from " + applicationName + "!";
    }
}
